<template>
  <view class="zdy-box">
    <uni-row v-if="config.listLayout == 'list'  && configLoaded">
      <!-- 普通列表布局 -->
      <view class="retail-list-block padding-0">
        <view class="retail-list-left-top" v-if="inPageType != 'detail'">
          <!-- filterTop -->
          <rFilter ref="filterTabs" v-if="tabs.length > 0 && validCols.length > 0" :tabs="tabs"
            :srv="config.serviceName" :cols="validCols" @on-input-value="onFilterChange" @on-change="getTableDatas">
          </rFilter>
        </view>
        <view class="retail-list-left-middle" v-if="tableLoaded">
          <uni-table border stripe emptyText="暂无更多数据">
            <!-- 表头行 -->
            <uni-tr>
              <uni-th align="center" v-for="(headCol,index) in gridHeader" :key="index">{{headCol.label}}
              </uni-th>
            </uni-tr>
            <!-- 表格数据行 -->
            <uni-tr v-for="(dataRow,index) in listData" :key="index">
              <uni-td v-for="(headCol,i) in gridHeader" :key="i">{{setColumnText(dataRow[headCol.columns])}}</uni-td>
            </uni-tr>
          </uni-table>
        </view>
        <view class="retail-list-left-bottom" v-if="inPageType != 'detail' && gridButton.length > 0">
        </view>
      </view>
    </uni-row>

    <uni-row v-if=" config.listLayout == 'listAndDetail' && configLoaded" class="retail-list">
      <!-- 左右两侧布局列表 -->
      <view class="retail-list-left bg-white">
        <view class="retail-list-left-top">
          <view class="button-group" v-if="config.hideGridButton!==true">
            <button @click="onGridButton(item)" class="g-button-light" v-for="(item,index) in gridButton" :key="index">
              <text class="cuIcon-roundaddfill add-icon" v-if="item.button_type == 'add'"></text>
              <text v-if="item.button_type == 'add'&&config.serviceName==='srvsys_app_role_select'">新增角色</text>
              <text v-else> {{item.button_name}}</text>
            </button>
          </view>
          <rFilter ref="filterTabs" :inListType="config.listLayout" v-if="tabs.length > 0 && gridHeader.length > 0"
            :tabs="tabs" :srv="config.serviceName" :cols="validCols" @on-input-value="onFilterChange"
            @on-change="getTableDatas"></rFilter>
        </view>
        <view class="retail-list-left-middle">
          <scroll-view class="scroll-left" :refresher-enabled="refresherEnabled" @refresherrefresh="reload()"
            :refresher-triggered="triggered" :refresher-threshold="80" :show-scrollbar="true" :scroll-y="true"
            @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
            <view class="" style="height: 50vh;display: flex;align-items: center;justify-content: center;"
              v-if="more==='noMore' && listData.length===0">
              <!-- <u-empty mode="list" text="暂无数据"></u-empty> -->
            </view>
            <uni-list :border="false">
              <uni-list-item :class="checkedItem && item.id == checkedItem.id ? 'avtive' : ''"
                v-for="(item,index) in listData" :key="index" :clickable="true" @click="onItemClick(item)">

                <!-- 自定义 header -->
                <template v-slot:header>
                </template>

                <!-- 自定义 body -->
                <template v-slot:body>
                  <view class="list-item-inline">
                    <slot name="rListItem" :item="item"> </slot>
                  </view>
                </template>
                <!-- 自定义 footer-->
                <template v-slot:footer>
                </template>
              </uni-list-item>

            </uni-list>
            <uni-load-more v-if="listType == 'swipe'" status="more"></uni-load-more>
          </scroll-view>
        </view>
        <view class="retail-list-left-bottom" v-if="gridButton.length > 0">
          <slot name="leftBottom" :sumValues="sumValues"></slot>
        </view>
      </view>
      <view class="retail-list-right show-y-scroll-bar">
        <view class="retail-list-right-top">
          <slot name="rightTop"></slot>
        </view>
        <view class="retail-list-right-middle show-y-scroll-bar">
          <slot name="rLayoutRight">
            <auth v-if="config.serviceName === 'srvsys_app_role_select'" :role-no="checkedItem?checkedItem.role_no:''"
              pageType="detail" ref="detailTree" @on-change="getTableDatas"></auth>
            <rDetail ref="rDetail" :detailTop="detailTop" v-else-if="checkedItem&&checkedItem.id"
              :detailLoaded="detailLoaded" :columnRowConfig="columnRowConfig"
              :item-id="checkedItem ? checkedItem.id: null" :service="config.serviceName" :rowButtons="rowButtons"
              :config="config" :isEditer="false" @data-change="getTableDatas">
            </rDetail>
          </slot>
        </view>
        <view class="retail-list-right-bottom">
          <slot name="rightBottom"></slot>
        </view>
      </view>
    </uni-row>
    <uni-row v-if="config.listLayout == 'listAndFilter'  && configLoaded" class="retail-list">
      <!-- 左右两侧布局列表  右边列表 -->
      <view class="retail-list-left bg-white">
        <view class="retail-list-left-top" v-if="gridButton.length > 0">
          <slot name="rFilter"></slot>
          <view class="button-group" v-if="config.hideGridButton!==true">
            <button @click="onGridButton(item)" class="g-button-light " v-for="(item,index) in gridButton" :key="index">
              <text class="cuIcon-roundaddfill add-icon" v-if="item.button_type == 'add'"></text>
              {{item.button_name}}
            </button>
          </view>

        </view>
        <view class="retail-list-left-middle shadow-warp full-height bg-white" style="overflow-y: initial;">
          <rFilter ref="filterTabs" :inListType="config.listLayout" :labelPos="'top'"
            v-if="tabs.length > 0 && gridHeader.length > 0 && configLoaded" :tabs="tabs" :srv="config.serviceName"
            :cols="validCols" @on-input-value="onFilterChange" @on-change="getTableDatas"></rFilter>
        </view>
        <view class="retail-list-left-bottom bg-white" v-if="gridButton.length > 0">
          <slot name="leftBottom"></slot>

          <!-- <button @click="onGridButton(item)" class="cu-btn block bg-blue margin-tb-sm lg" v-for="(item,index) in gridButton" :key="index">{{item.button_name}}</button> -->
        </view>
      </view>
      <view :class="classStyle" class="">
        <view class="retail-list-right-top">
          <slot name="rightTop" :allData="listData"></slot>
        </view>

        <view class="retail-list-right-middle  show-y-scroll-bar">
          <view class="loading-box" style="" v-if="!detailLoaded && more==='loading'">
            <u-loading-icon text="加载中" size="38" textSize="24"></u-loading-icon>
          </view>
          <view class="" style="height: 50vh;display: flex;align-items: center;justify-content: center;"
            v-if="moreRun==='noMore' && listData.length===0">
            <!-- <u-empty mode="list" text="暂无数据"></u-empty> -->
          </view>
          <!--          <view class="loading-box" v-else-if="listData.length===0&&moreRun==='noMore'">
            暂无更多数据
          </view> -->
          <uni-table class="retail-list-table show-y-scroll-bar" border stripe emptyText="暂无更多数据"
            v-else-if="listData.length>0" :type="selection?'selection':''" @selection-change="selectionChange"
            ref="rightTable">
            <!-- 表头行 -->
            <uni-tr v-if="gridHeader.length > 0">
              <uni-th :width="headCol.width||150" align="center" v-for="(headCol,index) in gridHeader" :key="index">
                {{headCol.label}}
              </uni-th>
              <uni-th width="200" v-if="config.showRowButton === true">操作</uni-th>
            </uni-tr>
            <!-- 表格数据行 -->
            <uni-tr v-for="(dataRow,index) in listData" :key="index">
              <uni-td v-for="(headCol,i) in gridHeader" :key="i">
                <view class="table-td-text" @click="onItemClick(dataRow)">
                  {{setColumnText(dataRow[headCol.columns])}}
                </view>
              </uni-td>
              <uni-td v-if="config.showRowButton === true">
                <text class="text-button" v-for="btn in rowButtons" v-show="isButtonDisplay(dataRow,btn,index)"
                  @click="onRowButton(dataRow,btn,index)">{{btn.button_name}}</text>
              </uni-td>
            </uni-tr>
          </uni-table>
          <slot name="rLayoutRight" v-if="gridHeader.length > 0">
          </slot>
          <view class="table-sum-panel padding lg" v-if="listData&&listData.length>0 && this.config.sumColumns">
            <text>总计:已提交</text>
            <text v-if="mainType==='quickInStcok'">入库</text><text v-if="mainType==='quickUpStcok'">出库</text>
            <text v-if="mainType==='stockCheckOff'">盘点</text><text v-if="mainType==='submittedLoss'">报损</text>
            <text>商品</text>
            <view class="text-red text-bold">{{`${sumValues.inNum||'0'}`}}</view>
            <text>,商品金额</text>
            <view class="text-red text-bold">{{`${sumValues.inAmount||'0'}`}}</view>
            <text>元；未提交</text>
            <text v-if="mainType==='quickInStcok'">入库</text><text v-if="mainType==='quickUpStcok'">出库</text>
            <text v-if="mainType==='stockCheckOff'">盘点</text><text v-if="mainType==='submittedLoss'">报损</text>
            <text>商品</text>
            <view class="text-red text-bold">{{`${sumValues.noNum||'0'}`}}</view>，商品金额 <view class="text-red text-bold">
              {{`${sumValues.noAmount||'0'}`}}
            </view>元
          </view>
          <slot name="rightBottom"></slot>

        </view>
        <view class="">
          <rpaging v-if="config.listLayout == 'listAndFilter' && gridHeader.length > 0" :inpage="listpage"
            @on-page-change="onpagintion"></rpaging>
        </view>
        <view class="retail-list-right-bottom padding" v-if="listData&&listData.length>0 ">
          <button v-if="showBatchSubmitRun" :disabled="selectedIndexs&&selectedIndexs.length===0"
            @click="onGridButton('batch-submit-checked')" class="g-button margin-right">提交选中</button>
          <button v-if="showBatchSubmitRun||(waitIds&&waitIds.length>0)" @click="onGridButton('batch-submit')"
            class="g-button">提交所有</button>
        </view>
      </view>
    </uni-row>
    <addMember @close="addNember" @success="addNember" :showRecharge.sync="showRecharge"
      v-if="config.listLayout == 'listAndDetail' && config.serviceName == 'srvretail_member_info_select'&&showUpdateMember"
      :show="showUpdateMember" :type="memberActionType"></addMember>
    <vip-recharge :show="showRecharge" @rechargeSuccess="rechargeSuccess" :curSelectMember="newMember"
      @close="showRecharge=false" @success="rechargeSuccess" v-if="showRecharge"></vip-recharge>
    <view class="custom-center-popup">
      <u-popup :show="showForm" mode="center" :round="20" :overlay="true" :closeable="false"
        :closeOnClickOverlay="false" @close="showForm = false">
        <view style="width: 80vw;" v-if="formService">
          <view class="popup-title" v-if="formService == 'srvretail_store_staff_update'">
            <!-- 编辑员工 -->
          </view>
          <bx-form :serviceName="formService" :appName="formApp" type="add" @on-submit="listChange"
            @cancel="showForm = false">
          </bx-form>
        </view>
      </u-popup>
      <u-popup :show="showSendCouponPopup" mode="center" :round="20" :overlay="true" :closeable="false"
        :closeOnClickOverlay="false" @close="showSendCouponPopup = false">
        <view class="popup-title">
          发放优惠券
        </view>
        <send-coupon v-if="showSendCouponPopup" :couponInfo="curCoupon" @cancel="showSendCouponPopup=false"
          @success="showSendCouponPopup=false"></send-coupon>

      </u-popup>
    </view>
  </view>
</template>

<script>
  import gBack from '@/components/g-batch-update/g-page-back.vue'
  import rFilter from '@/components/retail-list/retail-filter.vue'
  import rDetail from '@/components/listDetail/listDetail.vue'
  import rpaging from '@/components/bx-pagination/bx-pagination.vue'
  import addMember from "@/components/add-member/add-member.vue"
  import gStrIntercept from '@/components/g-batch-update/strIntercept.vue'
  import auth from '@/pages/main/auth/auth.vue'
  import {
    queryMembers
  } from '@/common/api/member.js'
  export default {
    name: "retail-list",
    components: {
      rFilter,
      rDetail,
      rpaging,
      addMember,
      gBack,
      gStrIntercept,
      auth
    },
    data() {
      return {
        formService: "",
        formApp: "",
        showForm: false,
        newMember: null,
        showRecharge: false,
        serviceV2: {},
        configLoaded: false,
        memberActionType: 'add', // 会员编辑类型
        showUpdateMember: false, // 会员信息新增，编辑
        listData: [],
        listType: "list", //
        searchVal: "",
        sumValues: {
          inNum: 0,
          inAmount: 0,
          noNum: 0,
          noAmount: 0
        },
        tabsBuild: false,
        tabs: [],
        filterCondition: [],
        relation_Conditions: {},
        checkedItem: null,
        detailLoaded: false, // 详情部分是否加载
        listpage: this.config.page ? this.config.page : {
          pageNo: 1,
          rownumber: 10
        },
        more: 'more', // more/loading/noMore
        triggered: false,
        refresherEnabled: true,
        relationCondition: null, // 过滤条件
        tabsType: "request", //request  custom
        tableLoaded: false, // 列表加载完成 与否 
        selectedIndexs: [],
        selectedList: [],
        waitIds: null,
        showSendCouponPopup: false, // 发放会员优惠券
        curCoupon: null,
      };
    },
    props: {
      mainType: {
        type: String
      },
      // 开启多选
      selection: {
        type: Boolean,
        default: false
      },
      detailTop: {
        type: String,
        default: function() {
          return '6rem'
        }
      },
      classStyle: {
        type: String,
        default: function() {
          return "retail-list-right padding"
        }
      },
      config: {
        type: Object,
        default: function() {
          return {
            serviceName: "srvretail_member_info_select",
            listLayout: "listAndDetail", // listAndDetail listAndFilter  list
            detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
            page: {
              pageNo: 1,
              rownumber: 10
            },
          }
        }
      },
      inPageType: {
        type: String,
        default: function() {
          return "list"
        }
      },
      columnRowConfig: {
        type: [Array],
        default: function() {
          return []
        }
      },
      heightTop: {
        type: String,
        default: function() {
          return "60px"
        }
      },
      searchValKey: {
        type: String,
        default: function() {
          return ""
        }
      },
      condition: {
        type: Array,
        default: function() {
          return []
        }
      },
      custGridHeader: {
        type: Array,
        default: function() {
          return []
        }
      }
    },
    computed: {
      srvApp() {
        return this.config?.srv_app || this.config?.appName || this.appName || uni.getStorageSync('activeApp')
      },
      showBatchSubmitRun: function() {
        let isShow = this.config.hasOwnProperty("showBatchSubmit") ? this.config.showBatchSubmit : false
        let list = []
        if (isShow) {
          list = this.listData.filter(item => item[isShow] == '待提交')
        }
        return isShow && list.length > 0
      },
      custTabsRun: function() {
        let cfg = this.config.custTabs || []
        return cfg
      },
      moreRun: function() {
        let more = this.more
        let page = this.listpage
        page.pageNo * page.rownumber < page.total ? more = 'more' : 'noMore'
        return more
      },
      validCols() {
        let cols = this.serviceV2.srv_cols || []
        cols = cols.filter((item) => item.in_list === 1 || item.in_list === 2)
        let res = []
        let confHeader = this.custGridHeader
        if (confHeader && confHeader.length > 0) {
          for (let col of confHeader) {
            for (let v2col of cols) {
              if (col == v2col.columns) {
                res.push(v2col)
              }
            }
          }

        } else {
          res = cols
        }
        return res || []
      },
      gridHeader: function() {
        let cols = this.serviceV2.srv_cols || []
        cols = cols.filter((item) => item.in_list == 1)
        let res = []
        let confHeader = this.custGridHeader
        if (confHeader && confHeader.length > 0) {
          for (let col of confHeader) {
            for (let v2col of cols) {
              if (col == v2col.columns) {
                res.push(v2col)
              }
            }
          }

        } else {
          res = cols
        }
        return res || []
      },
      conditionRun: function() {
        let cond = this.condition.concat(this.filterCondition)
        return cond
      },
      gridButton: function() {
        let buts = this.serviceV2.gridButton || []
        buts = buts.filter((item) => item.button_type == 'add')
        return buts || []
      },
      rowButtons: function() {
        let buts = this.serviceV2.rowButton || []
        buts = buts.filter((item) => item)
        return buts || []
      },
      cols: function() {
        let buts = this.serviceV2.srv_cols || []
        buts = buts.filter((item) => item.in_list == 1)
        return buts || []
      },
      moreConfig: function() {
        let cfg = this.serviceV2.more_config || {}
        let textStyle = {
          fontSize: 20,
          fontWeight: "bold",
          textAlign: "left",
        }
        let showConfig = {
          textStyle: textStyle,
          suffix: "",
          prefix: ""
        }
        let aioPage = {
          listType: "listAndDetail",
          listItem: [{
            colName: "member_name",
            colSpan: 1,
            colValType: "string", // string number 
            showConfig: showConfig

          }, {
            colName: "menber_no",
            colSpan: 0.5,
            colValType: "string", // string number 
            showConfig: showConfig
          }, {
            colName: "member_phone",
            colSpan: 0.5,
            colValType: "string", // string number 
            showConfig: showConfig
          }]
        }
        let listCfg = cfg.hasOwnProperty("aioPage") ? cfg.aioPage : aioPage
        return listCfg
      },
      relationConditionRun: function() {
        let relationCondition = {}
        let filterRelation = this.relationCondition
        let headerinputSearch = this.relation_Conditions
        if (filterRelation && filterRelation.data && filterRelation.data.length > 0) {
          relationCondition['data'] = filterRelation['data']
          relationCondition['relation'] = "AND"
          if (headerinputSearch && headerinputSearch.data && headerinputSearch.data.length > 0) {
            relationCondition['data'] = filterRelation['data'].concat(headerS.data)
          }
        }
        return relationCondition
      }
    },
    created() {
      this.getPageConfig()
    },
    updated() {
      // this.getListData()
    },
    methods: {
      toStockBatchSubmit(service, e) {
        let url = ''
        if (service == 'srvretail_issue_update') {
          url =
            `/pages/main/stockmgt/stock-batch-submit?serviceName=srvretail_issue_update&deleteService=srvretail_issue_delete&type=update&id=${e.id}&title=${e.issue_no}&childKeyCol=issue_no&titleText=快速出库&issue_state=${e.issue_state||''}`
        } else if (service == 'srvretail_warehousing_update') {
          url =
            `/pages/main/stockmgt/stock-batch-submit?serviceName=srvretail_warehousing_update&deleteService=srvretail_warehousing_delete&type=update&id=${e.id}&title=${e.warehousing_no}&childKeyCol=warehousing_no&titleText=快速入库&state=${e.warehousing_state||''}`
        } else if (service == 'srvretail_loss_reporting_update') {
          url =
            `/pages/main/stockmgt/stock-batch-submit?serviceName=srvretail_loss_reporting_update&deleteService=srvretail_loss_reporting_delete&type=update&id=${e.id}&title=${e.loss_no}&childKeyCol=loss_no&titleText=报损&state=${e.loss_state||''}`
        } else if (service == 'srvretail_inventory_update') {
          url =
            `/pages/main/stockmgt/stock-batch-submit?serviceName=srvretail_inventory_update&deleteService=srvretail_inventory_delete&type=update&id=${e.id}&title=${e.inventory_no}&childKeyCol=inventory_no&titleText=盘点&state=${e.inventory_state||''}`
        }

        if (e.operator_name) {
          url += `&operator_name=${e.operator_name}`
        }
        if (e.submit_time) {
          url += `&submit_time=${e.submit_time}`
        }
        if (e.create_time) {
          url += `&create_time=${e.create_time}`
        }
        uni.navigateTo({
          url: url
        })
      },
      async onRowButton(data, btn, index) {
        if (btn?.pre_confirm_msg) {
          let confirm = await new Promise(resolve => {
            uni.showModal({
              title: '提示',
              content: btn?.pre_confirm_msg,
              success: (res) => {
                if (res.confirm) {
                  resolve(true)
                } else {
                  resolve(false)
                }
              }
            })
          })
          if (confirm === false) {
            return
          }
        }

        let buttonInfo = this.deepClone(btn);
        let rowData = this.deepClone(data);
        if (buttonInfo.button_type === "edit") {
          if (['srvretail_issue_update', 'srvretail_warehousing_update', 'srvretail_loss_reporting_update',
              'srvretail_inventory_update'
            ].includes(buttonInfo.operate_service || buttonInfo.service_name)) {
            this.toStockBatchSubmit(buttonInfo.operate_service || buttonInfo.service_name, rowData)
            return
          }
        }
        if (buttonInfo?._buttons) {
          delete buttonInfo._buttons
        }

        let moreConfig = buttonInfo.more_config;
        if (moreConfig && typeof moreConfig === 'string') {
          try {
            buttonInfo.moreConfig = JSON.parse(moreConfig);
            moreConfig = buttonInfo.moreConfig
          } catch (e) {
            //TODO handle the exception
            console.log(e);
          }
        }

        if (!buttonInfo?.button_type) {
          uni.showModal({
            title: '提示',
            content: '按钮操作参数配置有误',
            showCancel: false
          })
          return
        }
        if (buttonInfo.operate_params && typeof buttonInfo.operate_params === 'string') {
          // 序列化操作参数
          try {
            buttonInfo.operate_params = JSON.parse(buttonInfo.operate_params);
            if (Array.isArray(buttonInfo.operate_params?.condition) && buttonInfo.operate_params.condition
              .length > 0) {
              buttonInfo.operate_params.condition.forEach(cond => {
                if (typeof cond.value === 'object' && cond.value.value_type === 'rowData') {
                  cond.value = rowData[cond.value.value_key];
                } else if (typeof cond.value === 'object' && cond.value.value_type ===
                  'constant') {
                  cond.value = cond.value.value;
                }
              });
            }
            if (Array.isArray(buttonInfo.operate_params?.data) && buttonInfo.operate_params.data.length >
              0) {
              buttonInfo.operate_params.data.forEach(data => {
                if (typeof data === 'object') {
                  Object.keys(data).forEach(item => {
                    if (typeof data[item] === 'object' && data[item].value_type ===
                      'rowData') {
                      data[item] = rowData[data[item].value_key];
                    } else if (typeof data[item] === 'object' && data[item]
                      .value_type === 'constant') {
                      data[item] = data[item].value;
                    }
                  });
                }
              });
            }
          } catch (e) {
            //TODO handle the exception
          }
        }
        if (buttonInfo.button_type === "customize") {
          if (buttonInfo.operate_type === '删除') {
            this.onButtonToUrl({
              row: data,
              button: buttonInfo
            }, this.srvApp).then(res => {
              if (res.state === 'SUCCESS') {
                // this.refresh()
                this.reload()
              }
            })
          } else if (['操作', '增加', '修改'].includes(buttonInfo.operate_type) && buttonInfo.operate_mode ===
            '静默操作') {

            let req = [{
              serviceName: buttonInfo.operate_service,
              condition: buttonInfo.operate_params.condition,
              data: buttonInfo.operate_params.data
            }];

            if (!buttonInfo.operate_params.data && buttonInfo.servcie_type === 'update') {
              uni.showModal({
                title: '提示',
                content: '按钮操作参数配置有误',
                showCancel: false
              })
              return
            }

            let app = buttonInfo.application || this.config?.appName || uni.getStorageSync('activeApp');
            let url = this.getServiceUrl(app, buttonInfo.operate_service, buttonInfo.servcie_type || 'operate');
            if (btn?.pre_confirm_msg) {
              this.$http.post(url, req).then(res => {
                uni.showToast({
                  title: res?.data?.resultMessage,
                  icon: 'none'
                })
                if (res.data.state === 'SUCCESS') {
                  this.reload()
                }
              })
            } else {
              let tipText = '是否确认操作'
              if (buttonInfo?.button_name === '生效' && !buttonInfo.tip_msg && rowData.promotion_name) {
                tipText = `是否确认将【${rowData.promotion_name}】生效`
              }
              let res = await new Promise(resolve => {
                uni.showModal({
                  title: '提示',
                  content: tipText,
                  success: (e) => {
                    if (e.confirm) {
                      resolve(true)
                    } else {
                      resolve(false)
                    }
                  }
                })
              })
              if (res === false) {
                return
              } else {
                this.$http.post(url, req).then(res => {
                  uni.showToast({
                    title: res?.data?.resultMessage,
                    icon: 'none'
                  })
                  if (res.data.state === 'SUCCESS') {
                    // this.refresh()
                    this.reload()
                  }
                })
              }

              // {
              //   uni.showModal({
              //     title: '提示',
              //     content: '是否确认操作?',
              //     success: (res) => {
              //       if (res.confirm) {
              //         this.$http.post(url, req).then(res => {
              //           uni.showToast({
              //             title: res?.data?.resultMessage,
              //             icon: 'none'
              //           })
              //           if (res.data.state === 'SUCCESS') {
              //             // this.refresh()
              //             this.reload()
              //           }
              //         })
              //       }
              //     }
              //   })
              // }
            }

            return
          } else if (buttonInfo.operate_type === "URL跳转") {} else if (buttonInfo.operate_type === '更新弹出' ||
            buttonInfo.operate_type === '更新跳转') {
            // 自定义按钮
            let moreConfig = buttonInfo.more_config;
            if (moreConfig && typeof moreConfig === 'string') {
              try {
                moreConfig = JSON.parse(moreConfig);
              } catch (e) {
                //TODO handle the exception
                console.log(e);
              }
            }
            if (buttonInfo.servcie_type === 'add') {
              debugger
            } else if (buttonInfo.servcie_type === 'select') {
              debugger
            } else if (buttonInfo.servcie_type === 'update' || buttonInfo.servcie_type === 'operate') {
              debugger
            }
            return
          } else if (buttonInfo.operate_type === '列表跳转') {
            debugger
          } else if (buttonInfo.operate_type === '详情跳转') {
            let fieldsCond = [];
            if (Array.isArray(buttonInfo.operate_params?.condition) && buttonInfo.operate_params.condition
              .length >
              0) {
              buttonInfo.operate_params.condition.forEach(item => {
                let obj = {
                  column: item.colName,
                  value: item.value,
                  disabled: true
                }
                fieldsCond.push(obj)
              })
            }
            let url =
              `/publicPages/formPage/formPage?type=detail&disabled=true&serviceName=${buttonInfo.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}&destApp=${buttonInfo.application}`;
            if (this.hideChildTable) {
              url += `&hideChildTable=true`
            }
            uni.navigateTo({
              url
            })
            return
          } else if (buttonInfo.operate_type === '增加跳转' || buttonInfo.operate_type === '增加弹出') {
            if (buttonInfo.button_name === '发放' && buttonInfo.service_name === "srvmkt_member_coupon_custom_add") {
              this.showSendCouponPopup = true
              this.curCoupon = rowData
              return
            }
            let fieldsCond = [];
            if (Array.isArray(buttonInfo.operate_params?.condition) && buttonInfo.operate_params.condition
              .length >
              0) {
              buttonInfo.operate_params.condition.forEach(item => {
                let obj = {
                  column: item.colName,
                  value: item.value,
                  disabled: true
                }
                fieldsCond.push(obj)
              })
            }
            if (Array.isArray(buttonInfo.operate_params?.data) && buttonInfo.operate_params.data.length >
              0) {
              buttonInfo.operate_params.data.forEach(item => {
                Object.keys(item).forEach(key => {
                  let obj = {
                    column: key,
                    value: item[key],
                    disabled: true
                  }
                  fieldsCond.push(obj)
                })

              })
            }
            let url =
              `/pages/public/form/form?type=add&serviceName=${buttonInfo.service_name}&fieldsCond=${JSON.stringify(fieldsCond)}&destApp=${buttonInfo.application}`;
            // uni.navigateTo({
            //   url
            // });
            if (this.hideChildTable) {
              url += `&hideChildTable=true`
            }
            let title = buttonInfo?.service_view_name || buttonInfo?.button_name
            this.navigateTo({
              url,
              title
            })
            return
          }

        } else {
          this.onButtonToUrl({
            row: data,
            button: buttonInfo
          }, this.srvApp).then(res => {
            if (buttonInfo && buttonInfo.button_type === 'delete') {
              if (res.state === 'SUCCESS') {
                // this.refresh()
                this.reload()
              }
            }
            if (buttonInfo && buttonInfo.button_type === 'detail') {
              let url =
                `/pages/public/form/form?serviceName=${buttonInfo.service_name}&type=detail&id=${data.id}`;
              if (this.config.appName) {
                url += `&appName=${this.config.appName}`
              }
              uni.navigateTo({
                url: url
              })
            } else if (buttonInfo && buttonInfo.button_type === 'customize') {
              // 自定义按钮
              let moreConfig = buttonInfo.more_config;
              if (moreConfig && typeof moreConfig === 'string') {
                try {
                  moreConfig = JSON.parse(moreConfig);
                } catch (e) {
                  //TODO handle the exception
                  console.log(e);
                }
              }

              if (buttonInfo.servcie_type === 'add') {
                let params = {
                  type: 'add',
                  serviceName: buttonInfo.service_name,
                  defaultVal: rowData,
                  eventOrigin: buttonInfo
                };

                let url = '/pages/public/formPage/formPage?params=' + JSON.stringify(
                  params)
                if (this.hideChildTable) {
                  url += `&hideChildTable=true`
                }

                uni.navigateTo({
                  url
                });

              } else if (buttonInfo.servcie_type === 'select') {
                let params = {
                  type: 'select',
                  serviceName: buttonInfo.service_name,
                  defaultVal: rowData,
                  eventOrigin: buttonInfo
                };
                if (buttonInfo.operate_params && Array.isArray(buttonInfo.operate_params
                    .condition)) {
                  let viewTemp = {};
                  if (buttonInfo.service_name ===
                    'srvhealth_store_vaccination_appoint_record_select') {
                    viewTemp = {
                      title: 'customer_name',
                      img: 'person_image',
                    }
                  }

                  let url = '/publicPages/list/list?pageType=list&serviceName=' +
                    buttonInfo.service_name +
                    '&cond=' +
                    JSON.stringify(buttonInfo.operate_params.condition) +
                    '&viewTemp=' +
                    JSON.stringify(viewTemp)

                  uni.navigateTo({
                    url
                  });
                }
              } else if (buttonInfo.servcie_type === 'update' || buttonInfo.button_type ===
                'edit') {
                let url =
                  `/pages/public/form/form?type=update&serviceName=${buttonInfo.service_name}&id=${data.id}&appName=${this.config.appName}`
                uni.navigateTo({
                  url
                })
              }
            } else if (buttonInfo.button_type ===
              'edit') {
              let url =
                `/pages/public/form/form?type=update&serviceName=${buttonInfo.service_name}&id=${data.id}&appName=${this.config.appName}`
              uni.navigateTo({
                url
              })
            } else if (buttonInfo && (buttonInfo.button_type === 'duplicate' || buttonInfo
                .button_type === 'duplicatedeep')) {
              console.log('duplicatedeep');
              let fieldsCond = []
              if (Array.isArray(this.condition)) {
                this.condition.forEach(item => {
                  fieldsCond.push({
                    column: item.colName,
                    value: item.value,
                    display: false
                  })
                })
              }
              console.log('fieldsCond:', fieldsCond);

              Object.keys(rowData).forEach(key => {
                if (!['id', 'modify_user_disp', 'modify_user', 'modify_time',
                    'create_user_disp', 'create_user', 'create_time', 'del_flag',
                    '_buttons'
                  ].includes(key) && rowData[key]) {
                  if (!fieldsCond.find(item => item.column === key)) {
                    fieldsCond.push({
                      column: key,
                      display: true,
                      value: rowData[key],
                    })
                  }
                }
              })
              console.log('fieldsCond2:', fieldsCond);
              let url =
                `/pages/public/form/form?serviceName=${buttonInfo.service_name}&type=add&fieldsCond=${JSON.stringify(fieldsCond)}`;
              if (this.config.appName) {
                url += `&appName=${this.config.appName}`
              }
              if (this.hideChildTable) {
                url += `&hideChildTable=true`
              }
              console.log('url,', url);
              uni.showModal({
                title: '提示',
                content: rowData.promotion_name ? `是否确认复制【${rowData.promotion_name}】` : '是否确认复制',
                confirmText: '确认',
                cancelText: '取消',
                success: (res) => {
                  if (res.confirm) {
                    uni.navigateTo({
                      url: url
                    });
                  } else {}
                }
              })

            } else if (buttonInfo.servcie_type === 'add') {
              let params = {
                type: 'add',
                serviceName: res.button.service_name,
                defaultVal: res.row,
                eventOrigin: res.button
              };


              uni.navigateTo({
                url: '/pages/public/formPage/formPage?params=' + JSON.stringify(
                  params)
              });
            } else if (buttonInfo && buttonInfo.operate_type === '流程申请') {
              uni.navigateTo({
                url: '/pages/public/proc/apply/apply?serviceName=' + buttonInfo
                  .operate_service
              });
            }
          });
        }

      },
      isButtonDisplay(data, btn, index) {
        if (btn.button_type === "duplicatedeep" || btn.button_type === "duplicate") {
          return false
        }
        // if (btn?.service_name === "srvmkt_promotion_activity_update" && btn.button_type === "edit") {
        // 	return false
        // }
        if (btn?.disp_exps) {
          return eval(btn?.disp_exps)
        }
        return true
      },
      listChange() {
        this.showForm = false;
        this.formService = ''
        this.formApp = ''
        this.getListData()
      },
      selectionChange(e) {
        this.selectedIndexs = e.detail.index
        this.selectedList = this.listData.filter((item, index) => e.detail.index.includes(index))
      },
      reload() {
        this.triggered = true
        this.$refs?.rightTable?.clearSelection()
        if (this.configLoaded) {
          this.listpage.pageNo = 1
          console.log('reload');
          this.getListData()
        }
        setTimeout(() => {
          this.triggered = false
        }, 3000)
      },
      getPageConfig() {
        let pageType = this.inPageType == 'detail' ? 'detaillist' : 'list'
        this.page = this.config.page
        this.tabsType = this.config.tabsType || 'request'
        if (this.configLoaded) {
          this.getListData()
        } else {
          this.getServiceV2(this.config.serviceName, 'select', pageType, this.config.appName).then((res) => {
            this.serviceV2 = res
            this.configLoaded = true
            if (this.tabsType == 'custom' && this.config.custTabs) {
              this.buildSections(this.config.custTabs, 'custom')
            }
            this.getListData()
          })
        }

      },
      getListData(pageNo, type) {
        let self = this
        self.tableLoaded = false
        let srv = this.serviceV2.service_name
        let cond = this.conditionRun
        let listType = type || 'swipe'
        let req = this.selectRequestObjs(srv, cond, null, this.relationConditionRun)
        // delete this.listpage.total
        req["page"] = this.listpage ? this.listpage : {
          pageNo: 1,
          rownumber: 5
        }
        if (pageNo) {
          req.page.pageNo = pageNo
        }
        console.log(pageNo);
        if (this.configLoaded) {
          this.detailLoaded = false
          this.more = 'loading'
          this.$fetch('select', srv, req, this.config.appName).then((res) => {
            if (res.success) {
              let listData = []
              if (pageNo !== 1 && pageNo !== null && pageNo !== undefined && listType == 'swipe') {
                listData = this.listData.concat(res.data)
              } else {
                this.listData = []
                listData = []
                listData = res.data
                if (res.data.length > 0) {
                  this.checkedItem = res.data[0]
                  this.$nextTick(() => {
                    this.$refs?.rDetail?.onReLoad()
                  })
                } else {
                  this.checkedItem = null
                }
              }
              setTimeout(() => {
                this.listData = listData.map((item) => item)
              }, 200)
              this.$set(this.listpage, 'pageNo', res.page.pageNo)
              this.$set(this.listpage, 'rownumber', res.page.rownumber)
              this.$set(this.listpage, 'total', res.page.total)
              if (res.page.pageNo * res.page.rownumber < res.page.total) {
                this.more = "more"
              } else {
                this.more = "noMore"
              }
              this.refresherEnabled = false
              setTimeout(() => {
                this.refresherEnabled = true
                this.triggered = false
              }, 100)
              this.tableLoaded = true // 列表加载完成
              this.getTableSum(res.data)
              this.getWaitId()
              this.detailLoaded = true
            }
          })
        }

      },
      rechargeSuccess(e) {
        this.showRecharge = false
        if (!e || e === 'SUCCESS') {
          uni.showToast({
            title: '充值成功'
          })
        } else if (e === 'USERPAYING') {
          // uni.showLoading({
          //   title: '用户支付中...'
          // })
          // uni.showToast({
          //   title: '用户支付中,请稍后刷新查看会员余额变动',
          //   icon: 'none'
          // })
        }
        this.getTableDatas()
      },
      addNember(e, showRecharge) {
        this.showUpdateMember = false
        queryMembers()
        if (e) {
          this.newMember = e;
          if (showRecharge) {
            // 会员充值弹窗
            this.showRecharge = true
          }
        }
        this.getTableDatas()
      },
      onGridButton(e) {
        let url = `/pages/public/form/form?serviceName=${e.service_name}&type=add`
        let inNavTo = false
        console.log(e);
        if (e?.button_type == 'add') {
          switch (e.service_name) {
            case "srvretail_warehousing_add":
              inNavTo = true
              url =
                `/pages/main/stockmgt/stock-batch-submit?serviceName=${e.service_name}&type=add&titleText=快速入库`
              break;
            case "srvretail_issue_add":
              inNavTo = true
              url =
                `/pages/main/stockmgt/stock-batch-submit?serviceName=${e.service_name}&type=add&titleText=快速出库`
              break;
            case "srvretail_inventory_add":
              inNavTo = true
              url =
                `/pages/main/stockmgt/stock-batch-submit?serviceName=${e.service_name}&type=add&titleText=盘点`
              break;
            case "srvretail_member_info_add":
            case "srvretail_member_custom_info_add":
              inNavTo = false
              this.showUpdateMember = true
              break;
            case "srvretail_loss_reporting_add":
              inNavTo = true
              url =
                `/pages/main/stockmgt/stock-batch-submit?serviceName=${e.service_name}&type=add&titleText=报损`
              // url = `/pages/main/stockmgt/stock-batch-submit?serviceName=${e.service_name}&type=add`
              break;
            case "srvretail_store_staff_add":
              inNavTo = false
              break;
            case "srvsys_app_role_add":
              this.$refs?.detailTree?.showPopup('add')
              break;
            case "srvmkt_promotion_activity_add":
              inNavTo = false
              break;
            default:
              break;
          }
        } else if (e === 'batch-submit-checked') {
          if (this.selectedList.length === 0) {
            uni.showToast({
              title: '请先在左侧勾选要操作的数据',
              icon: 'none'
            })
          } else {
            this.$emit("on-grid-button", {
              type: e,
              datas: this.selectedList
            })
          }
        } else {
          this.$emit("on-grid-button", {
            type: e,
            datas: this.listData,
            ids: this.waitIds
          })
        }
        if (inNavTo) {
          uni.navigateTo({
            url
          })
        } else if (e.service_name && !this.showUpdateMember && e.service_name !== 'srvsys_app_role_add') {
          this.formService = e.service_name
          this.formApp = e.application
          this.showForm = true
        }
      },
      onItemClick(e) {
        this.detailLoaded = false
        this.checkedItem = e
        // this.$nextTick(() => {
        setTimeout(() => {
          this.$emit("on-list-item-checked", e)
          if (this.config.listLayout !== 'listAndFilter' && this.config.serviceName !==
            'srvsys_app_role_select') {
            console.log('onReLoad');
            this.$refs.rDetail.onReLoad()
          }
          this.detailLoaded = true
        }, 100)
        // })

      },
      onSearch() {
        this.buildSearchCondition(this.searchVal, this.searchValKey)
      },
      upper(e) {
        console.log(e)
      },
      lower(e) {
        let self = this
        self.more = "loading"
        let page = self.deepClone(self.listpage)
        if ((page.pageNo * page.rownumber) < page.total) {
          self.listpage.pageNo = page.pageNo + 1
          self.getListData(page.pageNo + 1)
          console.log(page.pageNo + 1, self.listpage)
        } else {
          self.more = "noMore"
          uni.showToast({
            icon: "none",
            title: "没有更多了"
          })
        }

      },
      scroll(e) {
        // console.log(e)
      },
      buildSections(tabs, type) { // type custom request  
        let self = this
        let tab = {}
        let tabsData = []
        if (type && type == 'custom') {
          tabs.forEach((t, index) => {
            tab = {
              service: null,
              table_name: null,
              orders: null,
              conditions: null,
              seq: null,
              parent: null,
              label: null,
              list_tab_no: null,
              more_config: null,
              inputType: null,
              custom_options: t.custom_options
            }
            console.log(t);
            tab.service = t.service || ''
            tab.prefixIcon = t.prefixIcon || ''
            tab._colName = t.colName.split(',') || null
            tab._type = t.type || null
            tab.inputType = t.inputType || null
            tab.colspan = t.colspan
            tab.label = t.label
            tab.placeholder = t.placeholder || t.type === 'Select' || t._type === 'select' ? '请选择' :
              '请输入'
            tab.showAllTag = t.showAllTag || false
            tab.list_tab_no = t.list_tab_no || 'custom' + index
            tab._data = t
            tab.showLabel = t.showLabel
            tab.appendSearchButton = t.appendSearchButton || false
            tab._options = [] // 选项列表数据
            tab.option_list = t.options || null // 配置
            if (tab._colName) {
              let cols = tab._colName
              let srvCols = self.validCols
              tab['_colSrvData'] = []
              // console.log("tab",tab)
              for (let c = 0; c < cols.length; c++) {
                for (let cs = 0; cs < srvCols.length; cs++) {
                  if (cols[c] === srvCols[cs].columns) {
                    tab._colSrvData.push(srvCols[cs])
                  }
                }
              }

            }
            if (tab.inputType == 'tree' && Array.isArray(t.option_list_v2)) {
              tab._options = t.option_list_v2
              // .map((item) => {
              //   let itemVal = {
              //     text: item.label || item.text,
              //     value: item.value,
              //     children:item.children
              //   }
              //   return itemVal
              // })
            }
            if (tab.inputType == 'fk') {
              let cond = [{
                "colName": tab.option_list.key_disp_col,
                "ruleType": "[like]",
                "value": ''
              }]
              cond = cond.concat(tab.option_list ? tab.option_list.conditions : [])
              // cond.push(tab.option_list.conditions)
              console.log("build option ", tab)
              let req = this.selectRequestObjs(tab.option_list.serviceName, cond, null, this
                .relationCondition)
              req.page = {
                rownumber: 100
              }
              let options = []
              this.$fetch('select', tab.option_list.serviceName, req, this.config.appName).then((
                res) => {
                let resData = res.data
                for (let i = 0; i < resData.length; i++) {
                  let item = resData[i]
                  let opt = {
                    value: item[tab.option_list.refed_col],
                    label: item[tab.option_list.key_disp_col],
                    text: item[tab.option_list.key_disp_col]
                  }
                  options.push(opt)
                }

                // self.formModel[e.list_tab_no]['options'] = options
                tab["_options"] = options
                tab["page"] = res.data.page
                // return options
                console.log("options", options)
                //  resolve(options)
              })


            } else if (tab.inputType === 'enum' && tab.custom_options) {
              tab._options = [{
                text: '全部',
                value: "_unlimited_"
              }, ...tab.custom_options]
            } else if (tab.inputType == 'enum' && tab._colSrvData.length > 0 && Array.isArray(tab._colSrvData[0]
                .option_list_v2)) {
              let colOptions = tab._colSrvData[0].option_list_v2
              tab._options = colOptions.map((item) => {
                let itemVal = {
                  text: item.label,
                  value: item.value
                }
                return itemVal
              })
              if (Array.isArray(tab._options) && tab._options.length > 0 && tab._options[0].text !==
                '全部') {
                tab._options = [{
                  text: '全部',
                  value: "_unlimited_"
                }, ...tab._options]
              }
            } else if (tab.inputType == '#staff#') {
              let colOptions = uni.getStorageSync('persistData').$staffList || []
              console.log('colOptions', colOptions)
              colOptions = colOptions.filter(item => item.staff_status == '在职')
              tab._options = colOptions.map((item) => {
                let itemVal = {
                  text: item.name,
                  value: item.staff_no
                }
                return itemVal
              })
              if (Array.isArray(tab._options) && tab._options.length > 0 && tab._options[0].text !==
                '全部') {
                tab._options = [{
                  text: '全部',
                  value: "_unlimited_"
                }, ...tab._options]
              }
            }
            tabsData.push(tab)
          })
        } else {
          tabs.forEach((t) => {
            tab = {
              service: null,
              table_name: null,
              orders: null,
              conditions: null,
              seq: null,
              parent: null,
              label: null,
              list_tab_no: null,
              more_config: null,
              inputType: null
            }

            let mc = JSON.parse(t.more_config)
            // console.log("JSON.parse",t.more_config,JSON.parse(t.more_config))
            tab.more_config = JSON.parse(t.more_config)
            tab.service = t.service
            tab.table_name = t.table_name
            tab.conditions = mc.option_list ? mc.option_list.conditions : null || []
            tab.orders = t.orders
            tab.default = mc.default
            tab.seq = t.seq
            tab.label = t.label
            tab.list_tab_no = t.list_tab_no
            tab._data = t
            tab._options = []
            tab._type = mc.type || null
            tab.option_list = JSON.parse(t.more_config).option_list || null
            tab._colName = mc.colName || null
            tab.inputType = mc.inputType || null
            tab.showAllTag = mc.showAllTag || false
            tab.default = mc.default || '',
              tab.placeholder = mc.placeholder || mc.type === 'select' ? '请选择' : '请输入'
            tab.remoteMethod = ""

            if (tab._colName) {
              tab._colName = tab._colName.split(',')
              let cols = tab._colName
              let srvCols = self.validCols
              tab['_colSrvData'] = []
              // console.log("tab",tab)
              for (let c = 0; c < cols.length; c++) {
                for (let cs = 0; cs < srvCols.length; cs++) {
                  if (cols[c] === srvCols[cs].columns) {
                    tab._colSrvData.push(srvCols[cs])
                  }
                }
              }

            }
            if (tab.inputType == 'fk') {
              let cond = [{
                "colName": tab.option_list.key_disp_col,
                "ruleType": "[like]",
                "value": ''
              }]
              cond = cond.concat(tab.option_list ? tab.option_list.conditions : [])
              // cond.push(tab.option_list.conditions)
              console.log("build option ", tab)
              let req = this.selectRequestObjs(tab.option_list.serviceName, cond, null, this
                .relationCondition)
              let options = []
              this.$fetch('select', tab.option_list.serviceName, req, this.config.appName).then((
                res) => {
                let resData = res.data.data
                for (let i = 0; i < resData.length; i++) {
                  let item = resData[i]
                  let opt = {
                    value: item[tab.option_list.refed_col],
                    label: item[tab.option_list.key_disp_col]
                  }
                  options.push(opt)

                }
                if (Array.isArray(options) && options.length > 0 && options[0].label !==
                  '全部') {
                  options = [{
                    label: '全部',
                    value: "_unlimited_"
                  }]
                }
                tab["_options"] = options
                tab["page"] = res.data.page
                // return options
                console.log("options", options)
                //  resolve(options)
              })
            }
            tabsData.push(tab)
          })
        }

        if (tabsData.length > 0 && !self.tabsBuild) {
          self.tabs = tabsData
          self.tabsBuild = true
        }
      },
      onFilterChange(e) {
        let self = this
        // this.onInputValue = e
        if (e && self.$refs.filterTabs) {
          let tabsConds = self.$refs.filterTabs.buildConditions()
          self.relationCondition = tabsConds
        }
      },
      getTableDatas() {
        let self = this
        let tabsConds = self.$refs.filterTabs ? self.$refs.filterTabs.buildConditions() : {}
        // this.$set('relationCondition',tabsConds)
        this.relationCondition = tabsConds
        // this.listpage.pageNo = 0
        this.$nextTick(() => {
          console.log('getTableDatas');
          this.getListData(1)
        })

        //console.log("tabsConds",tabsConds)
      },
      onpagintion(e) {
        console.log("onpagintion", e)
        this.getListData(e, "pagintion")
      },
      getWaitId() {
        let self = this
        let srv = this.serviceV2.service_name
        let cond = this.conditionRun
        this.waitIds = []
        if (self.tableLoaded && this.config.listLayout == 'listAndFilter' && this.config.sumColumns) {
          let req = {
            "serviceName": srv,
            "colNames": [
              "id"
            ],
            "condition": [{
              colName: this.config.sumColumns.state,
              ruleType: "eq",
              value: "待提交"
            }, ],
            page: {
              rownumber: 500
            },
            "group": [{
              "colName": 'id',
              "type": "by"
            }]
          }
          self.$fetch('select', srv, req, this.config.appName).then((res) => {
            if (res.success) {
              console.log(res.data);
              if (Array.isArray(res.data) && res.data.length > 0) {
                this.waitIds = res.data.map(item => item.id)
              }
            }
          })
        }
      },
      getTableSum(list) {
        let self = this
        let srv = this.serviceV2.service_name
        let cond = this.conditionRun
        console.log(cond);
        if (self.tableLoaded && this.config.listLayout == 'listAndFilter' && this.config.sumColumns) {
          let req = {
            "serviceName": srv,
            "colNames": [
              "*"
            ],
            "condition": [],
            "group": [{
              "colName": this.config.sumColumns.state,
              "type": "by"
            }, {
              "colName": this.config.sumColumns.num,
              "type": "sum"
            }, {
              "colName": this.config.sumColumns.amount,
              "type": "sum"
            }]
          }
          let tabsConds = self.$refs.filterTabs ? self.$refs.filterTabs.buildConditions() : {};

          req.relation_condition = tabsConds

          // if (Array.isArray(list) && list.length > 0) {
          //   // req.condition = [{
          //   //   colName: 'id',
          //   //   ruleType: 'in',
          //   //   value: list.map(item => item.id).toString()
          //   // }]
          // }
          self.$fetch('select', srv, req, this.config.appName).then((res) => {
            if (res.success) {
              let sumData = res.data
              self.sumValues = {
                inNum: 0,
                inAmount: 0,
                noNum: 0,
                noAmount: 0
              }
              for (let data of sumData) {
                switch (data[this.config.sumColumns.state]) {
                  case '待提交':
                    self.$set(self.sumValues, 'noNum', data[this.config.sumColumns.num])
                    self.$set(self.sumValues, 'noAmount', data[this.config.sumColumns.amount])
                    break;
                  case '已提交':
                    self.$set(self.sumValues, 'inNum', data[this.config.sumColumns.num])
                    self.$set(self.sumValues, 'inAmount', data[this.config.sumColumns.amount])
                    break;
                  default:
                    break;
                }
              }
            }
          })
        }

      }
    },
    watch: {
      "tableLoaded": function(newVal, oldVal) {
        if (newVal == true) {
          this.$emit("table-loaded", newVal)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .zdy-box /deep/ .retail-list .retail-list-left {
    height: unset;
    width: calc(100vw - 70%) !important;
    /* overflow: hidden; */
  }

  .zdy-box /deep/ uni-radio::before {

    margin-top: -8px !important;
    right: 5px !important;
    font-size: 1.4rem !important;

  }

  $bottom-button-height:8rem;
  $bottom-button-font-size:2rem;
  $middle-body-height:calc(100vh - 16rem);
  $padding:0.5rem 1.7rem;

  .retail-list {
    width: 100%;
    height: 100%;
    // background-color: $retail-color-primary;
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    .retail-list-block {
      width: 100%;

      .retail-list-left-middle {}
    }

    ::v-deep .uni-scroll-view-refresher {
      background-color: transparent !important;
    }

    .retail-list-left {
      // padding: $padding;
      background-color: #fff;
      height: 100%;
      width: calc(100vw - 70%);
      padding: 1rem;

      .retail-list-left-middle {
        // background-color: #f5f5f5;
        border-radius: 1rem;

        .scroll-left {
          max-height: calc(100vh -20rem);
          height: 100%;
        }

        &,
        .full-height {
          height: 100%;
        }
      }
    }

    .retail-list-left,
    .retail-list-block {
      // padding: 20upx;
      // background-color: #f2f2f2;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .retail-list-left-middle {
        overflow-y: auto;
        padding: 1rem;

        .list-item-inline {
          width: 100%;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        }

        .uni-list {
          background-color: transparent;

          &:before {
            display: none;
          }
        }

        .uni-list-item {
          color: #000;
          font-weight: 600;
          border-radius: 1rem;

          &.avtive {
            border: 0.1rem solid $retail-color-primary;
            background-color: $retail-color-primary-light;
          }
        }
      }

      .retail-list-left-top {

        // height: $bottom-button-height;
        // display: flex;
        // flex-direction: row;
        .cu-btn.lg {
          height: $bottom-button-height;
          font-size: $bottom-button-font-size;
        }
      }

      .retail-list-left-bottom {
        // height: $bottom-button-height;
        display: flex;
        flex-direction: row;
        justify-content: space-between;

        .cu-btn.lg {
          height: $bottom-button-height;
          font-size: $bottom-button-font-size;
        }
      }
    }

    .retail-list-right {
      padding: $padding;
      // margin: $padding;
      width: calc(100vw - 25%);
      border-radius: 0.4rem;

      overflow: hidden;
      overflow-y: auto;
      background-color: #f2f2f2;
      display: flex;
      flex-direction: column;
      // max-height: calc(100vh - 260rpx);
      justify-content: space-between;

      &.height-full {
        height: calc(100vh - 6rem) !important;
      }

      .retail-list-right-middle {
        height: 100%;
        // border-radius: 2rem;
        overflow: hidden;
        position: relative;

        .loading-box {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          min-height: 50rem;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          z-index: 999;
          background-color: rgba(255, 255, 255, 0.7);
          font-size: 2.4rem;
        }

        .list-item-inline {
          width: 100%;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        }

        overflow-y: auto;
      }

      .retail-list-right-bottom {
        display: flex;
        justify-content: flex-end;
        // height: $bottom-button-height;
      }
    }

    .uni-list {
      background-color: #f2f2f2;

      .uni-list-item {
        padding: $padding;
        margin-bottom: 1rem !important;
      }
    }
  }

  .text-button {
    color: #38c09e;
    display: inline-block;
    padding: 1rem;
  }

  .retail-list-table {
    // overflow-x: auto;

    // ::v-deep .uni-table {
    //   overflow-x: auto;
    // }
  }

  .send-coupon {
    ::v-deep .uni-select {
      height: 6.8rem;
      line-height: 6.8rem;

      .uni-select__input-text {
        font-size: 2.4rem;
      }
    }
  }

  ::v-deep .uni-table {
    .uni-table-tr:nth-child(n + 2):hover {
      background-color: #DEF2EA !important;
    }
  }
</style>
